project(audio-processing)

file(GLOB audio_processing_sources
        "aec_dump/null_aec_dump_factory.cc"
        "aec3/adaptive_fir_filter.cc"
        "aec3/adaptive_fir_filter_erl.cc"
        "aec3/aec3_common.cc"
        "aec3/aec3_fft.cc"
        "aec3/aec_state.cc"
        "aec3/alignment_mixer.cc"
        "aec3/api_call_jitter_metrics.cc"
        "aec3/block_buffer.cc"
        "aec3/block_delay_buffer.cc"
        "aec3/block_framer.cc"
        "aec3/block_processor.cc"
        "aec3/block_processor_metrics.cc"
        "aec3/clockdrift_detector.cc"
        "aec3/coarse_filter_update_gain.cc"
        "aec3/comfort_noise_generator.cc"
        "aec3/decimator.cc"
        "aec3/dominant_nearend_detector.cc"
        "aec3/downsampled_render_buffer.cc"
        "aec3/echo_audibility.cc"
        "aec3/echo_canceller3.cc"
        "aec3/echo_path_delay_estimator.cc"
        "aec3/echo_path_variability.cc"
        "aec3/echo_remover.cc"
        "aec3/echo_remover_metrics.cc"
        "aec3/erle_estimator.cc"
        "aec3/erl_estimator.cc"
        "aec3/fft_buffer.cc"
        "aec3/filter_analyzer.cc"
        "aec3/frame_blocker.cc"
        "aec3/fullband_erle_estimator.cc"
        "aec3/matched_filter.cc"
        "aec3/matched_filter_lag_aggregator.cc"
        "aec3/moving_average.cc"
        "aec3/refined_filter_update_gain.cc"
        "aec3/render_buffer.cc"
        "aec3/render_delay_buffer.cc"
        "aec3/render_delay_controller.cc"
        "aec3/render_delay_controller_metrics.cc"
        "aec3/render_signal_analyzer.cc"
        "aec3/residual_echo_estimator.cc"
        "aec3/reverb_decay_estimator.cc"
        "aec3/reverb_frequency_response.cc"
        "aec3/reverb_model.cc"
        "aec3/reverb_model_estimator.cc"
        "aec3/signal_dependent_erle_estimator.cc"
        "aec3/spectrum_buffer.cc"
        "aec3/stationarity_estimator.cc"
        "aec3/subband_erle_estimator.cc"
        "aec3/subband_nearend_detector.cc"
        "aec3/subtractor.cc"
        "aec3/subtractor_output_analyzer.cc"
        "aec3/subtractor_output.cc"
        "aec3/suppression_filter.cc"
        "aec3/suppression_gain.cc"
        "aec3/transparent_mode.cc"
        "aecm/aecm_core.cc"
        "aecm/aecm_core_c.cc"
        "aecm/echo_control_mobile.cc"
        "agc/agc.cc"
        "agc/agc_manager_direct.cc"
        "agc/clipping_predictor_evaluator.cc"
        "agc/clipping_predictor.cc"
        "agc/clipping_predictor_level_buffer.cc"
        "agc/legacy/analog_agc.cc"
        "agc/legacy/digital_agc.cc"
        "agc/loudness_histogram.cc"
        "agc/utility.cc"
        "agc2/adaptive_agc.cc"
        "agc2/adaptive_digital_gain_applier.cc"
        # "agc2/adaptive_mode_level_estimator_agc.cc"
        "agc2/adaptive_mode_level_estimator.cc"
#        "agc2/agc2_testing_common.cc"
        "agc2/biquad_filter.cc"
        "agc2/compute_interpolated_gain_curve.cc"
        "agc2/cpu_features.cc"
        "agc2/down_sampler.cc"
        "agc2/fixed_digital_level_estimator.cc"
        "agc2/gain_applier.cc"
        "agc2/interpolated_gain_curve.cc"
        "agc2/limiter.cc"
        "agc2/limiter_db_gain_curve.cc"
        "agc2/noise_level_estimator.cc"
        "agc2/noise_spectrum_estimator.cc"
        "agc2/rnn_vad/auto_correlation.cc"
        # "agc2/rnn_vad/common.cc"
        "agc2/rnn_vad/features_extraction.cc"
        "agc2/rnn_vad/lp_residual.cc"
        "agc2/rnn_vad/pitch_search.cc"
        "agc2/rnn_vad/pitch_search_internal.cc"
        "agc2/rnn_vad/rnn.cc"
        "agc2/rnn_vad/rnn_fc.cc"
        "agc2/rnn_vad/rnn_gru.cc"
        "agc2/rnn_vad/spectral_features.cc"
        "agc2/rnn_vad/spectral_features_internal.cc"
        "agc2/saturation_protector.cc"
        "agc2/saturation_protector_buffer.cc"
        "agc2/signal_classifier.cc"
        "agc2/vad_with_level.cc"
        "agc2/vector_float_frame.cc"
        "audio_buffer.cc"
        "audio_processing_builder_impl.cc"
        "audio_processing_impl.cc"
        "capture_levels_adjuster/audio_samples_scaler.cc"
        "capture_levels_adjuster/capture_levels_adjuster.cc"
        "echo_control_mobile_impl.cc"
        "echo_detector/circular_buffer.cc"
        "echo_detector/mean_variance_estimator.cc"
        "echo_detector/moving_max.cc"
        "echo_detector/normalized_covariance_estimator.cc"
        "gain_control_impl.cc"
        "gain_controller2.cc"
        "high_pass_filter.cc"
        "include/aec_dump.cc"
        "include/audio_frame_proxies.cc"
        "include/audio_processing.cc"
        "include/audio_processing_statistics.cc"
        "include/config.cc"
        "level_estimator.cc"
        "logging/apm_data_dumper.cc"
        "ns/fast_math.cc"
        "ns/histograms.cc"
        "ns/noise_estimator.cc"
        "ns/noise_suppressor.cc"
        "ns/ns_fft.cc"
        "ns/prior_signal_model.cc"
        "ns/prior_signal_model_estimator.cc"
        "ns/quantile_noise_estimator.cc"
        "ns/signal_model.cc"
        "ns/signal_model_estimator.cc"
        "ns/speech_probability_estimator.cc"
        "ns/suppression_params.cc"
        "ns/wiener_filter.cc"
        "optionally_built_submodule_creators.cc"
        "residual_echo_detector.cc"
        "rms_level.cc"
        "splitting_filter.cc"
        "three_band_filter_bank.cc"
        "transient/file_utils.cc"
        "transient/moving_moments.cc"
        "transient/transient_detector.cc"
        "transient/transient_suppressor_impl.cc"
        "transient/wpd_node.cc"
        "transient/wpd_tree.cc"
        "typing_detection.cc"
        "utility/cascaded_biquad_filter.cc"
        "utility/delay_estimator.cc"
        "utility/delay_estimator_wrapper.cc"
        "utility/pffft_wrapper.cc"
        "vad/gmm.cc"
        "vad/pitch_based_vad.cc"
        "vad/pitch_internal.cc"
        "vad/pole_zero_filter.cc"
        "vad/standalone_vad.cc"
        "vad/vad_audio_proc.cc"
        "vad/vad_circular_buffer.cc"
        "vad/voice_activity_detector.cc"
        "voice_detection.cc")

if ("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
    file(GLOB webrtc_audio_processing_privatearch_sources
            "aec3/adaptive_fir_filter_avx2.cc"
            "aec3/adaptive_fir_filter_erl_avx2.cc"
            "aec3/fft_data_avx2.cc"
            "aec3/matched_filter_avx2.cc"
            "aec3/vector_math_avx2.cc"
            "agc2/rnn_vad/vector_math_avx2.cc")
endif ()

add_library(${PROJECT_NAME} ${LIB_TYPE} ${audio_processing_sources} ${webrtc_audio_processing_privatearch_sources})

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../webrtc)
target_compile_definitions(${PROJECT_NAME} PUBLIC WEBRTC_APM_DEBUG_DUMP=1)

target_link_libraries(${PROJECT_NAME} PUBLIC rtc-base webrtc-api system-wrappers common-audio pffft rnnoise)